package com.burgeon.backend.college.client_side.controller;

import com.burgeon.backend.EnterpriseWeChat.controller.EWBaseController;
import com.burgeon.backend.college.client_side.entity.Exam;
import com.burgeon.backend.college.client_side.service.AppCollegeService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;


@CrossOrigin
@RestController
@RequestMapping("ewapp/college")
public class AppCollegeController extends EWBaseController {
    @Autowired
    private AppCollegeService appCollegeService;

    //申请复考
    @RequestMapping("applyAfterTest")
    public ResponseResult<Void> applyAfterTest(String exam_id, String emp_id) {

        appCollegeService.applyAfterTest(exam_id, emp_id);

        return new ResponseResult<>(SUCCESS);
    }

    //课件
    @RequestMapping("getCourseware")
    public ResponseResult<HashMap> getCourseware(String id, Integer start) {
        HashMap data = appCollegeService.getCourseware(id, start);
        return new ResponseResult<HashMap>(SUCCESS, data);
    }


    /**
     * 课程列表
     *
     * @param empId 导购id
     * @param token
     * @return
     */
    @RequestMapping("getCourseList")
    public ResponseResult<HashMap> getCourseList(String empId, String token) {
        HashMap data = appCollegeService.getCourseList(empId, token);
        return new ResponseResult<HashMap>(SUCCESS, data);
    }

    /**
     * 开始学习 创建学习记录
     *
     * @param course_id 课程id
     * @param empId     导购id
     * @param token
     * @return
     */
    @RequestMapping("startCourse")
    public ResponseResult<String> startCourse(String course_id, String empId, String token,String storeId) {
        String data = appCollegeService.startCourse(course_id, empId, token,storeId);
        return new ResponseResult<String>(SUCCESS, data);
    }

    /**
     * 记录学习过程 每分钟执行
     *
     * @param course_id 课程id
     * @param empId     导购姓名
     * @param token
     * @return
     */
    @RequestMapping("recordLearning")
    public ResponseResult<HashMap> recordLearning(String course_id, String empId, String token) {
        HashMap data = appCollegeService.recordLearning(course_id, empId, token);
        return new ResponseResult<HashMap>(SUCCESS, data);
    }

    /**
     * 开始考试 返回试题
     *
     * @param course_id 课程id
     * @return
     */
    @RequestMapping("startExam")
    public ResponseResult<Exam> startExam(String course_id) {
        Exam data = appCollegeService.startExam(course_id);
        return new ResponseResult<Exam>(SUCCESS, data);
    }

    /**
     * 考试完成
     *
     * @param exam_id 考试id
     * @param empId
     * @param score   答对分数
     * @param correct 答对题数
     * @param time    完成时间 mm:ss
     * @param count   答对分数
     * @param token
     * @return
     */
    @RequestMapping("examResult")
    public ResponseResult<Void> examResult(String exam_id, String empId, Integer score,
                                           Integer correct, String time, Integer count,
                                           String token,String storeId) {

        appCollegeService.examResult(exam_id, empId, score, correct, time, count, token,storeId);
        return new ResponseResult<>(SUCCESS);
    }

    /**
     * 考试结果数据
     *
     * @param examId 考试id
     * @param empId
     * @return
     */
    @RequestMapping("getExamResultData")
    public ResponseResult<HashMap> getExamResultData(String examId, String empId) {

        HashMap data = appCollegeService.getExamResultData(examId, empId);
        return new ResponseResult<HashMap>(SUCCESS, data);
    }


}
